package com.lanou.pianke.search.service.impl;

import com.lanou.pianke.search.EntityRepository.PcommentRepository;
import com.lanou.pianke.search.entity.Pcomment;
import com.lanou.pianke.search.service.PcommentService;
import org.elasticsearch.index.query.QueryStringQueryBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

@Service
public class PcommentServiceImpl implements PcommentService {

    @Autowired
    private PcommentRepository pcommentRepository;

    @Override
    public List<Pcomment> searchByPcommentContent(String searchContent) {
        QueryStringQueryBuilder builder = new QueryStringQueryBuilder(searchContent);
        Iterable<Pcomment> search = pcommentRepository.search(builder);
        Iterator<Pcomment> iterator = search.iterator();
        List<Pcomment> pcommentList = new ArrayList<>();
        while (iterator.hasNext()){
            pcommentList.add(iterator.next());
        }
        return pcommentList;
    }
}
